package com.net.xpay.common.manager.impl.partner;

import com.google.common.base.Preconditions;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractVersionedManager;
import com.net.xpay.common.dao.partner.PartnerWithdrawRecordMapper;
import com.net.xpay.common.domain.partner.PartnerWithdrawRecord;
import com.net.xpay.common.manager.partner.PartnerWithdrawRecordManager;
import com.net.xpay.common.model.search.PartnerWithdrawRecordSearchModel;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;


@Component
@ReadTransactional
public class PartnerWithdrawRecordManagerImpl extends AbstractVersionedManager<PartnerWithdrawRecord> implements PartnerWithdrawRecordManager{

    @Autowired
    private PartnerWithdrawRecordMapper mapper;


    @Override
    protected BasicMapper<Long, PartnerWithdrawRecord> getMapper() {
        return mapper;
    }

    @Override
    public List<PartnerWithdrawRecord> search(PartnerWithdrawRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(PartnerWithdrawRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public List<PartnerWithdrawRecord> listByIds(List<Long> ids) {
        Preconditions.checkArgument(CollectionUtils.isNotEmpty(ids));

        return nonEmptyList(mapper.listByIds(ids));
    }

    @Override
    public long statTransferMoney(LocalDateTime minEndTime, LocalDateTime maxEndTime) {
        Preconditions.checkArgument(minEndTime != null && maxEndTime != null);
        return mapper.statTransferMoney(minEndTime, maxEndTime);
    }

    @Override
    public long sumPartnerWithdrawRecordStat(PartnerWithdrawRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.sumPartnerWithdrawRecordStat(searchModel);
    }

    @Override
    public List<PartnerWithdrawRecord> list(PartnerWithdrawRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return nonEmptyList(mapper.list(searchModel));
    }


}
